/*Author: Seungbeom Ma
 *SJSU 
 * DATE: NOV 16
 * */
/**
 * 
 * 
 * */
//
/**
 * 
 * 
 * */
package tool.writefile;
/**
 * Name: Seungbeom Ma
 * SJSU
 * FOR Project for mobile close
 * NOV 28 2013
 * 
 * */

import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.util.ArrayList;

import android.os.Environment;
import android.util.Log;

public class ReportBuilder extends Thread {
	
	 ArrayList<String> Node_Size = new ArrayList<String>();
	 ArrayList<String> Ex_Time = new ArrayList<String>();
	 ArrayList<String> D_Time = new ArrayList<String>();
	 
	 public ReportBuilder(ArrayList<String> Node_Size, ArrayList<String> Ex_Time  ,ArrayList<String> D_Time ){
		 this.Node_Size = Node_Size;
		 this.Ex_Time = Ex_Time;
		 this.D_Time= D_Time;
		 
	 }
	 public void run(){
		Log.d("ReportBuilder", "Building Repot file");
		
        try{
        	String path;
        	int index = 0;
        	while(true){
        		path = Environment.getExternalStorageDirectory() +"/"+ index+".txt";
        		File file = new File(path);
        		if(file.exists()) {
            	   index++;	
            	}
        		else{
        			break;
        		}
        	}
        	System.out.println(path);
        	FileOutputStream fOut = new FileOutputStream(path);
             OutputStreamWriter osw = new OutputStreamWriter(fOut);
             for(int i = 0 ; i < Node_Size.size() ; i++){
            	 osw.write(Node_Size.get(i) + ";"+ Ex_Time.get(i) +";" +D_Time.get(i));
             }
             
             osw.flush();
             osw.close();
         }catch(Exception e){
                  e.printStackTrace();
         }      
    }
	
}


